package com.ymatou.shoppingcart.api.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.shoppingcart.api.parameter.DeleteFromCartByUserBean;
import com.ymatou.shoppingcart.api.service.DeleteFromCartByUserCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.database.mongo.ShopCartMongoBean;
import com.ymttest.database.mongo.ShoppingCartMongoWapper;
import com.ymttest.utils.constant.ECode;

/**
 * 根据UserId删除购物车中记录 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_DeleteFromCartByUser {
	private static DeleteFromCartByUserBean deluserbean;
	private static DeleteFromCartByUserCall delusercall;
	ShoppingCartMongoWapper scw;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据UserId删除购物车中记录");
	}

	@Before
	public void caseUp() {
		deluserbean = new DeleteFromCartByUserBean();
		delusercall = new DeleteFromCartByUserCall();
		try {
			scw = new ShoppingCartMongoWapper();
		} catch (Exception e) {
			Logger.setup("MongoDB初始化失败：" + e.getMessage(), -1);
		}
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(delusercall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	//TODO 购物车表和结构都有修改，case需要对应调整
	
	/*@Test
	@Category(P1.class)
	@TestCase
	public void Tc_DeleteFromCartByUser_001() {
		Logger.start(true,"根据UserId删除购物车中记录成功");
		try {
			Logger.comment("从mongodb中获取一条购物车记录");

			ShopCartMongoBean re = scw.getOneShoppingCartInfo("{}");
			int count = scw.getShoppingCartCount("{\"uid\":\"" + re.getUid() + "\"}");
			Logger.comment("用户:" + re.getUid() + "有" + count + "条记录");
			Logger.comment("setUserId：" + re.getUid());
			deluserbean.setUserId(re.getUid());
			delusercall.setData(deluserbean);
			delusercall.callService();
			Logger.comment("delusercall send:" + delusercall.getEntityString());
			Logger.comment("delusercall return:" + delusercall.getReturnData());
			Logger.verifyEquals(ECode.SUCCESS, delusercall.getCode(), "验证返回code");
			Logger.verifyEquals(ECode.BCODE0, delusercall.getBCode(), "验证返回bcode");
			count = scw.getShoppingCartCount("{\"uid\":\"" + re.getUid() + "\"}");
			Logger.comment("用户:" + re.getUid() + "有" + count + "条记录");
			Logger.verifyEquals(0, count, "验证count条数");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_DeleteFromCartByUser_002() {
		Logger.start(true,"不输入必填项UserId，删除购物车中记录失败");
		try {
			Logger.comment("从mongodb中获取一条购物车记录");

			ShopCartMongoBean re = scw.getOneShoppingCartInfo("{}");
			int count = scw.getShoppingCartCount("{\"uid\":\"" + re.getUid() + "\"}");
			Logger.comment("用户:" + re.getUid() + "有" + count + "条记录");
			// Logger.comment("setUserId："+re.getUid());
			// deluserbean.setUserId(re.getUid());
			delusercall.setData(deluserbean);
			delusercall.callService();
			Logger.comment("delusercall send:" + delusercall.getEntityString());
			Logger.comment("delusercall return:" + delusercall.getReturnData());
			Logger.verifyEquals(ECode.ERROR500, delusercall.getCode(), "验证返回code");
			Logger.verifyEquals(ECode.BCODE0, delusercall.getBCode(), "验证返回bcode");
			Logger.verifyEquals(true, delusercall.getMsg().contains(ECode.ERROR500_MSG_2), "验证返回Msg是否包含字符:"
					+ ECode.ERROR500_MSG_2);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}*/
}